$(function() {
	         var url_modify = "/ag/zlw/modify_ShiftType.action";               // 一些url
	         var url_find = "/ag/zlw/find_ShiftType.action";
	         var url_add = "/ag/zlw/add_ShiftType.action";
	         var url_delete = "/ag/zlw/delete_ShiftType.action"
			$("#dialog").dialog("destroy");
		var name = $("#name"), allFields = $( []).add(name), tips = $(".validateTips");

		function updateTips(t) {
			tips.text(t).addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight', 1500);
			}, 500);
		}

		function checkLength(o, n, min, max) {
			var dtDealingType1 = $.trim(o.val());
			var cArr1 = dtDealingType1.match(/[^x00-xff]/ig);
			var the_length = dtDealingType1.length
					+ (cArr1 == null ? 0 : cArr1.length);
			if (the_length > max || the_length < min) {
				o.addClass('ui-state-error');
				updateTips(n + "长度必须在 " + min + " 和 " + (max/2) + "之间.");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o, regexp, n) {
			if (!(regexp.test(o.val()))) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		/** **********************修改begin***************************** */
		$('.modify').click(function() {                        // 点修改
			var id_val = $.trim($(this).parent().siblings(".id_").text()); // 取兄弟即id的内容放到弹出form
			var name_val = $.trim($(this).parent().siblings(".name_")
					.text());
			$("input[name='name_modify']").val(name_val);
			$("input[name='id_modify']").val(id_val);
			$('#dialog-form-modify').dialog('open');
		});
		
		
		$("#dialog-form-modify").dialog( { // 修改form的情况
					autoOpen : false,
					height : 200,
					width : 350,
					modal : true,
					buttons : {
						'提交' : function() {
							name = $("input[name='name_modify']");
							
						
							var bValid = true;			
							allFields.removeClass('ui-state-error');
							bValid = bValid && checkLength(name, "名字", 1, 10);						
							if (bValid) {
								$("#confirmUI_modify").dialog('open');
							}
						},
						'取消' : function() {
							$(this).dialog('close');
						}
					},
					close : function() {
						allFields.val('').removeClass('ui-state-error');
					}
				});

		$("#confirmUI_modify").dialog( { // 修改时的confirm
					autoOpen : false,
					height : 100,
					width : 350,
					modal : true,
					buttons : {
						'修改' : function() {
							$("button[name='修改']").attr("disabled", "disabled");
							allFields.removeClass('ui-state-error');
							/* 这里提交 */
							var psId = $("input[name='id_modify']").val();
							var psShift = $("input[name='name_modify']").val();			
							var req = {
									psId :psId,
									psShift : psShift
							};
							var url = url_modify;
							$.post(url, req, function(data) { // 传入到action
										result_alert(data);
									});
							/* 提交结束 */
						},
						'取消' : function() {
							$(this).dialog('close');
						}
					},
					close : function() {
						allFields.val('').removeClass('ui-state-error');
					}
				});

	/** ***********************修改end ***************************** */
		/** **********删除begin******************* */
		$('button.delete').click(function() {
			$('#confirmUI_delete').dialog('open');
			var Id_val = $.trim($(this).parent().siblings(".id_").text()); // 取兄弟即id的内容放到弹出form			
			$("input[name='id_delete']").val(Id_val);
		});			
		$("#confirmUI_delete").dialog( { // 修改时的confirm
			autoOpen : false,
			height : 100,
			width : 350,
			modal : true,
			buttons : {
				'删除' : function() {
					$("button[name='删除']").attr("disabled", "disabled");
					allFields.removeClass('ui-state-error');
					/* 这里提交 */
					var psId = $("input[name='id_delete']").val();					
					var req = {
							psId : psId
					};
					var url = url_delete;
					$.post(url, req, function(data) { // 传入到action
								result_alert(data);
							});
					/* 提交结束 */
				},
				'取消' : function() {
					$(this).dialog('close');
				}
			},
			close : function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		
		
		/** **********删除end******************* */
		
		/* *************返回成功与否begin ******************* */
		function result_alert(data) {
			$("div[name='alert']").text(data.message).dialog('open');
		}
		$("div[name='alert']").dialog( {
			autoOpen : false,
			height : 100,
			width : 350,
			modal : true,
			buttons : {
				'确定' : function() {
					allFields.removeClass('ui-state-error');
					location.href = url_find;
				}
			},
			close : function() {
				allFields.val('').removeClass('ui-state-error');
				location.href = url_find;
			}
		});

		/** **************** 返回成功与否end ***************** */
		/** **************** 增加begin ***************** */
		$('#create-user').click(function() {
			$('#dialog-form').dialog('open');
		});
		
		$("#dialog-form").dialog( {                 // 增加form的情况
					autoOpen : false,
					height : 200,
					width : 350,
					modal : true,
					buttons : {
						'保存' : function() {
							name = $("input[name='name_add']");							
							var bValid = true;
							allFields.removeClass('ui-state-error');
							bValid = bValid && checkLength(name, "名字", 1, 10);							
							if (bValid)
								$("#confirmUI_add").dialog('open');
						},
						'取消' : function() {
							$(this).dialog('close');
						}
					},
					close : function() {
						allFields.val('').removeClass('ui-state-error');
					}
				});

		$("#confirmUI_add").dialog( {                // 增加confirm
					autoOpen : false,
					height : 100,
					width : 350,
					modal : true,
					buttons : {
						'增加' : function() {
							$("button[name='增加']").attr("disabled", "disabled");
							allFields.removeClass('ui-state-error');
							/* 这里提交 */
							var psShift = $("input[name='name_add']").val();							
							var req = {						
									psShift : psShift							
							};
							var url = url_add;
							$.post(url, req, function(data) { // 传入到action
										result_alert(data);
									});
							/* 提交结束 */
						},
						'取消' : function() {
							$(this).dialog('close');
						}
					},
					close : function() {
						allFields.val('').removeClass('ui-state-error');
					}
				});


/*		$("tr.list").mouseover(function() {                                 //行跟着鼠标闪效果
			$(this).children().css("background-color", "#66FFFF");
		}).mouseout(function() {
			$(this).children().css("background-color", "white");
		});
*/
	});